package com.smooware.icms.fragment.navigation;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.util.Log;

import com.smooware.icms.fragment.wo.WODashboardFragment;
import com.smooware.icms.fragment.wo.WOShedulesFragment;

public class WOFragmentNavigator extends AbstractFragmentNavigator {

	private static final String TAG = WOFragmentNavigator.class.getSimpleName();

	public WOFragmentNavigator(final FragmentActivity holder) {
		super(holder);
	}

	@Override
	public void processAuthorizationFragment() {
		if (!holder.getSupportActionBar().isShowing()) {
			holder.getSupportActionBar().show();
		}

		goToWOSheduleFragment();
	}

	/**
	 * Navigates to {@link WOShedulesFragment}. Adds it if there is no fragment
	 * shown at the moment, or replace it if there is non-
	 * {@link WOShedulesFragment} instance shown at the moment.
	 */
	public void goToWOSheduleFragment() {
		Fragment fragment = new WOShedulesFragment();

		if (navigatorHelper.isFragmentFrameEmpty()) {

			navigatorHelper.addFragment(fragment);
		} else if (!(navigatorHelper.getCurrentFragment() instanceof WOShedulesFragment)) {

			navigatorHelper.replaceFragmentAndPushInBackStack(fragment);
		} else {
			Log.d(TAG, "do nothing in " + TAG);
		}
	}

	public void goToWODashboardFragment() {
		Fragment fragment = new WODashboardFragment();

		if (navigatorHelper.isFragmentFrameEmpty()) {

			navigatorHelper.addFragment(fragment);
		} else if (!(navigatorHelper.getCurrentFragment() instanceof WODashboardFragment)) {

			navigatorHelper.replaceFragment(fragment);
		} else {
			Log.d(TAG, "do nothing in " + TAG);
		}
	}
}
